/******************************************************************
 * Copyright (c) 2007 - 2007, Simon Guerard, All rights reserved.
 * 
 * Projet de jeu de course au large.
 * 
 * This File is part of Sail-Race
 * 
 * Sail-Race is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * Sail-Race is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * Sail-Race; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA 02110-1301 USA
 */
package net.simcafamily.sailrace.vues;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Properties;

import javax.swing.JButton;
import javax.swing.JPanel;

import net.simcafamily.sailrace.core.AbstractView;

import com.bbn.openmap.LayerHandler;
import com.bbn.openmap.MapBean;
import com.bbn.openmap.MapHandler;
import com.bbn.openmap.gui.BasicMapPanel;
import com.bbn.openmap.gui.OMToolSet;
import com.bbn.openmap.gui.ToolPanel;
import com.bbn.openmap.layer.GraticuleLayer;
import com.bbn.openmap.layer.imageTile.ImageTileLayer;
import com.bbn.openmap.layer.shape.ShapeLayer;
import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

@org.springframework.stereotype.Component("vueRace")
public class VueRace extends AbstractView {
    JPanel contentPane;

    // affiche
    /**
     * @wbp.parser.entryPoint
     */
    @Override
    public Component buildContentPane() {
	// affichage classe parent
	contentPane = new JPanel();
	contentPane.setLayout(new FormLayout(new ColumnSpec[] {
		ColumnSpec.decode("default:grow"),
		ColumnSpec.decode("150px:grow"), },
		new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, }));

	BasicMapPanel mapPanel = new BasicMapPanel();
	// Get the default MapHandler the BasicMapPanel created.
	MapHandler mapHandler = mapPanel.getMapHandler();
	mapHandler.add(baseVue);

	// Get the default MapBean that the BasicMapPanel created.
	MapBean mapBean = mapPanel.getMapBean();
	mapBean.setCenter(47, -3);
	mapBean.setAutoscrolls(true);
	mapBean.setScale(3750000f);

	mapBean.setBackground(Color.BLUE);
	ImageTileLayer layer = new ImageTileLayer();
	Properties layerProps = new Properties();
	layerProps.put("imageFilePath", "resources");
	layer.setProperties(layerProps);
	ShapeLayer shapeLayer = new ShapeLayer(
		"f:\\dev\\sail-race\\resources\\france.shp");
	Properties shapeProps = new Properties();
	shapeProps.put("lineColor", Color.BLACK);
	shapeProps.put("fillColor", Color.WHITE);
	shapeLayer.setProperties(shapeProps);

	/*
	 * Create and add a LayerHandler to the MapHandler. The LayerHandler
	 * manages Layers, whether they are part of the map or not.
	 * layer.setVisible(true) will add it to the map. The LayerHandler has
	 * methods to do this, too. The LayerHandler will find the MapBean in
	 * the MapHandler.
	 */
	mapHandler.add(new LayerHandler());
	mapHandler.add(shapeLayer);
	mapHandler.add(layer);
	mapHandler.add(new GraticuleLayer());
	// Create the directional and zoom control tool
	OMToolSet omts = new OMToolSet();
	// Create an OpenMap toolbar
	ToolPanel toolBar = new ToolPanel();

	/*
	 * Add the ToolPanel and the OMToolSet to the MapHandler. The
	 * OpenMapFrame will find the ToolPanel and attach it to the top part of
	 * its content pane, and the ToolPanel will find the OMToolSet and add
	 * it to itself.
	 */
	mapHandler.add(omts);
	mapHandler.add(toolBar);

	contentPane.add(mapPanel, "1, 1, fill, default");

	JButton btnRetour = new JButton("Retour");
	btnRetour.addActionListener(new ActionListener() {
	    @Override
	    public void actionPerformed(ActionEvent event) {
		baseVue.setActionName("infosActionIntro");
		baseVue.getSynchro().set();
	    }
	});
	contentPane.add(btnRetour, "2, 1");
	// shapeFile = new ShapeFile(new File(shpFile));

	return contentPane;
    }
}
